function toCamelCase(str) {  
	return str.replace(/([-_][a-z])/gi, function($1){return $1.toUpperCase().replace('-','').replace('_','')});  
}  
// 处理成小驼峰
const camelCase = (arr)=>{
	const newArr = arr.map(obj => {
		const newObj={} 
		for (const key in obj) {
			if (obj.hasOwnProperty(key)) {
				const camelCaseKey = toCamelCase(key)
				newObj[camelCaseKey] = obj[key]; 
			}
		}
		return newObj
	})
	return newArr
}
//生成uuid
const generateUUID = ()=> {
	return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
	  const r = Math.random() * 16 | 0;
	  const v = c === 'x' ? r : (r & 0x3 | 0x8);
	  return v.toString(16);
	});
  }
const atDate = () =>{
	const now = new Date();  
	const year = now.getFullYear();  
	const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以加1，并补零  
	const day = String(now.getDate()).padStart(2, '0'); // 补零   
  	return `${year}-${month}-${day}`;
}
/**@description 根据id字段返回 文字
 *         元数据     比较字段     目标字段值      文字字段
 * @param {source:array,key:string,target:string,label:string} obj 
 * @returns string
 */
const mapTxt = (obj) =>{
	const {source,key,target,label} = obj
	if(!source){ 
		return ''
	}
	let result=''
	for(let i=0;i<source.length;i++){
		if(source[i][key]==target){
			result = source[i][label]
			break;
		}
	}
	return result
}
module.exports = {
	camelCase,
	atDate,
	mapTxt,
	generateUUID
}